home *** CD-ROM | disk | FTP | other *** search
- Path: hecate.umd.edu!bs05
- From: bs05@csc.umd.edu (CMSC 420)
- Newsgroups: comp.lang.c++
- Subject: help with stream read/write
- Date: 20 Feb 1996 20:47:14 GMT
- Organization: University of Maryland, College Park
- Message-ID: <4gdc0i$cje@hecate.umd.edu>
- NNTP-Posting-Host: holmes.umd.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- I'm trying to write an array of floats to a file and then read it back.
- When I do, everything is ok for the first 141 array elements (a[0] to a[140]).
- After that, the array is garbage. Can someone look at the code snippet?
-
- const int len = 200;
- float a[len];
-
- // fill array
- float x = 0.0;
- for (int n=0; n<len; ++n)
- a[n] = (x += 1.0);
-
- // write array to file
- ofstream outfile("data");
- outfile.write((unsigned char*) a, len*sizeof(float));
- outfile.close();
-
- // read array from file
- ifstream infile("data");
- infile.read((unsigned char*) a, len*sizeof(float));
- infile.close();
-
-